<template>
	<view>
		<!-- 居中弹出 -->
		<gui-popup ref="guipopup" width="600rpx" :zIndex="1000" @close="closed">
			<view class="gui-relative">
				<!-- 关闭按钮 -->
				<text class="gui-block demo-close gui-icons gui-absolute-rt" @tap.stop="close">&#xe78a;</text>
				<view class="img_warp gui-flex gui-justify-content-center">
					<image class="msg_img" src="@/static/index/msg_warning.png" mode="widthFix"></image>
				</view>
				<view class="content">
					<view class="txt f30">
						{{dataRes.context}}
					</view>
				</view>
				<view class="btn_warp gui-flex gui-justify-content-center gui-align-items-center">
					<view class="saveBtn" @tap="close">
						确定
					</view>
				</view>
			</view>
		</gui-popup>
	</view>
</template>

<script setup>
	let plugin = requirePlugin("WechatSI");
	const emit = defineEmits(['closed'])
	let manager = plugin.getRecordRecognitionManager();

	const props = defineProps({
		title: String,
		dataRes: {
			type: Object,
			default: null
		}
	})
	import {
		selectPromptByOne
	} from '@/api/app.js';
	import {
		ref
	} from 'vue'
	const guipopup = ref(null)
	var music = null;

	const open = () => {
		guipopup.value.open();
		setTimeout(() => {
			bobao();
		}, 200)

	}

	const close = () => {
		if (music) {
			music.stop();
			music.destroy();
			music = null;
		}
		guipopup.value.close();
	}

	const bobao = () => {
		console.log(props.dataRes.context);
		let _this = this;
		plugin.textToSpeech({
			lang: "zh_CN",
			tts: true,
			content: props.dataRes.context,
			success: function(res) {
				music = uni.createInnerAudioContext(); //创建播放器对象
				music.src = res.filename;
				music.play(); //执行播放
				music.onEnded(() => {
					music = null;
				});
			},
			fail: function(res) {
				// console.log("fail tts", res)
			}
		})
	}

	const closed = () => {
		emit('closed')
	}

	// 抛出函数
	defineExpose({
		open,
		close
	})
</script>

<style lang="scss">
	.gui-relative {
		position: relative;
		width: 600rpx;
		// min-height: 660rpx;
		background-color: #fff;
		border-radius: 16rpx;
		overflow: hidden;
	}

	.img_warp {
		margin-top: 113rpx;
	}

	.msg_img {
		width: 119rpx;
		height: auto;
	}

	.content {
		margin-top: 40rpx;
		padding: 0 80rpx;
		box-sizing: border-box;
		text-align: center;
	}

	.btn_warp {
		height: 80rpx;
		width: 100%;
		margin-bottom: 66rpx;
		margin-top: 32rpx;

		.saveBtn {
			width: 456rpx;
			height: 64rpx;

			&.cel {
				background: #fff;
				color: #666666;
			}
		}
	}

	.demo-close {
		width: 100rpx;
		height: 100rpx;
		color: #c0c0c0;
		line-height: 100rpx;
		opacity: 0.88;
		text-align: center;
		font-size: 38rpx;
	}
</style>